from flask import Flask, jsonify, request
from generateMedAndComp import getCompKeyword23

# 创建 Flask 应用
app = Flask(__name__)

# JSON 数据路由
@app.route('/api/data', methods=['GET'])
def api_data():
    # 从查询参数中获取 'src_search_file_path' 和 'seed_keyword'
    src_search_file_path = request.args.get('src_search_file_path')
    seed_keyword = request.args.get('seed_keyword')

    # 如果没有传入参数，可以设置默认值或返回错误
    if not src_search_file_path or not seed_keyword:
        return jsonify({"error": "Both 'src_search_file_path' and 'seed_keyword' are required."}), 400

    print(src_search_file_path)
    print(seed_keyword)

    getCompKeyword23(src_search_file_path, seed_keyword)
    # 构造返回的数据
    data = {
        "name": "Flask App",
        "version": "1.0",
        "status": "Running",
        "src_search_file_path": src_search_file_path,
        "seed_keyword": seed_keyword
    }

    return jsonify(data)  # 返回 JSON 格式的响应


if __name__ == '__main__':
    # 启动 Flask 应用
    app.run(debug=True,port=8050)
